package com.jeomo.shiro.util;

import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.util.ByteSource;

/**
 * <h3>jeomo</h3>
 * <p>密码工具类</p>
 *
 * @author : qibotian
 * @date : 2020-10-29 16:53
 **/
public class PasswordUtil {

    public static String entryPassword(String topOrgCode, String username, String password) {
        String salt = getSalt(topOrgCode, username);
        //加密方式
        String hashAlgorithmName = "MD5";
        //盐：为了即使相同的密码不同的盐加密后的结果也不同
        ByteSource byteSalt = ByteSource.Util.bytes(salt);
        //密码
        Object source = password;
        //加密次数
        int hashIterations = 1024;
        SimpleHash result = new SimpleHash(hashAlgorithmName, source, byteSalt, hashIterations);
        return result.toString();
    }

    public static String getSalt(String topOrgCode, String username) {
        return topOrgCode + username;
    }

    public static void main(String[] args) {
        System.out.println(entryPassword("000", "superAdmin", "123456"));
    }
}
